package cn.ctyun.ipush.controller;

import cn.ctyun.ipush.service.ProdService;
import cn.ctyun.ipush.service.SaleService;
import cn.ctyun.ipush.utils.ConfigUtils;
import cn.ctyun.ipush.web.user.bo.UserModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by yanghongbo on 2017/5/10.
 */
@Controller
public class BonusControl {

    @Autowired
    private SaleService saleService;

    @Autowired
    private ProdService prodService;

    @RequestMapping(value = "bonusDYIntoPage", method = RequestMethod.GET)
    public ModelAndView intoPage(HttpSession session, HttpServletRequest request) {
        /**
         * bonusIntoPage 需要返回当前用户的信息
         */
        try {

            UserModel o = (UserModel) session.getAttribute("userInfo");
            if (o != null) {
                String sql = String.format("select a.*,b.prod_name,b.prod_type from  hbbt_sales_his_model a inner join hbbt_product_model b on a.prod_id=b.hbbt_product_model_id where a.is_deleted='0' and a.create_userid='%s'", o.getUserModelId());
                List list = saleService.queryListBySql(ConfigUtils.getStringValue("jdbcUrl"), ConfigUtils.getStringValue("username"), ConfigUtils.getStringValue("password"), sql);
                Map<String, Object> data = new HashMap<String, Object>();
                data.put("hbbtSalesHisModelList", list);
                return new ModelAndView("IB_DY_SEARCHBONUS", data);
            } else {
                return new ModelAndView("IB_DY_SEARCHBONUS", null);
            }
        } catch (Exception e) {
            return new ModelAndView("IB_DY_SEARCHBONUS", null);
        }
    }




    @RequestMapping(value = "bonusDZIntoPage", method = RequestMethod.GET)
    public ModelAndView intoDZPage(HttpSession session, HttpServletRequest request) {
        /**
         * bonusIntoPage 需要返回当前用户的信息
         */

        try {
            Object o = session.getAttribute("userInfo");
            if (o != null) {

                return new ModelAndView("IB_DZ_SEARCHBONUS", null);

            }
            return new ModelAndView("IB_DZ_SEARCHBONUS", null);
        } catch (Exception e) {
            e.printStackTrace();
            return new ModelAndView("IB_DZ_SEARCHBONUS", null);
        }
    }
}
